// custom-tab-bar/inex.js
import tui from '../common/httpRequest'
Component({
  /**
   * 组件的属性列表  因为需要弹框遮住tabbar,所以做了自定义tabbar
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    tabBar: [ {
      pagePath: "/pages/tabBar/index/index",
      text: "首页",
      iconPath: "/static/images/tabBar/index2.png",
      selectedIconPath: "/static/images/tabBar/index.png"
    },
    {
      pagePath: "/pages/tabBar/task/index",
      text: "任务",
      iconPath: "/static/images/tabBar/list.png",
      selectedIconPath: "/static/images/tabBar/list2.png"
    },
    {
      pagePath: "/pages/tabBar/examine/index",
      text: "审核",
      iconPath: "/static/images/tabBar/examine2.png",
      selectedIconPath: "/static/images/tabBar/examine.png",
      num:0,
      isDot:true

    },
    {
      pagePath: "/pages/tabBar/my/index",
      text: "个人中心",
      iconPath: "/static/images/tabBar/my.png",
      selectedIconPath: "/static/images/tabBar/my2.png"
    }
  ],
  current: '0'
  },
created(){
this.getDetail()
},
  /**
   * 组件的方法列表
   */
  methods: {

    async getDetail(){
      // 需审核有没有数据
      const res = await tui.request('sys/task/userAuditTask', 'GET', {
        name:wx.getStorageSync('name'),
      }, true);
      console.log(res)
      if(res.code==20000){
        console.log(res.data,'res.data.data')
       
        if(res.data==1){
          console.log('xiaban ')
          getApp().globalData.ifExemine=1
          this.setData({
            ['tabBar[2].num']:1
          })
        }else{
          console.log('xiabanxiabanxiabanxiabanxiaban ')
          getApp().globalData.ifExemine=0
          this.setData({
            ['tabBar[2].num']:0
          })
        }
        console.log(this.data.tabBar)
      }

    },
    tabbarSwitch(e) {
console.log('tabbarSwitch')
this.getDetail()
      const data = e.detail
      const url = data.pagePath
      wx.switchTab({ url,success: function (e) {
        var page = getCurrentPages().pop();
        // if (page == undefined || page == null) return;
        page.onLoad();
      } })
      this.setData({
        current: data.index
      })
     
    }

  }
})
